<template>
  <div>
    <input placeholder="输入关键字搜索" v-model="haha" @keyup.enter="add"/>
    <Hospital :records="records" @getCount="shuashua"></Hospital>
    <Statement v-if="flag" @getCount1="kuakua" :index='index' :records="records"></Statement>
  </div>
</template>

<script>
import Hospital from "./components/Hospital.vue"
import Statement from "./components/Statement.vue"
export default {
  components: {
    Hospital,
    Statement
  },
  data() {
    return {
      flag:false,
      haha: '',
      index:'',
      records: [
        {
          date: "2022-01-01",
          doctor: "张三",
          diagnosis: "感冒",
          prescription: "感冒药",
        },
        {
          date: "2022-02-01",
          doctor: "李四",
          diagnosis: "头疼",
          prescription: "止疼药",
        },
        {
          date: "2022-03-01",
          doctor: "王五",
          diagnosis: "腰痛",
          prescription: "止痛贴",
        },
      ],
    };
  },
  methods: {
    add() {
      this.records = this.records.filter(item => item.doctor === this.haha)
      if(this.records == '') {
       this.records = [
        {
          date: "2022-01-01",
          doctor: "张三",
          diagnosis: "感冒",
          prescription: "感冒药",
        },
        {
          date: "2022-02-01",
          doctor: "李四",
          diagnosis: "头疼",
          prescription: "止疼药",
        },
        {
          date: "2022-03-01",
          doctor: "王五",
          diagnosis: "腰痛",
          prescription: "止痛贴",
        },
      ]
      }
    },
    shuashua(flag,index) {
      console.log(flag);
      this.flag = flag
      this.index= index
    },
    kuakua(flag) {
      console.log(flag);
      this.flag = flag
    }
  }
}

</script>

<style>
</style>
